package com.learning.spring.cloud.ms.provider.user.controller;

import com.learning.spring.cloud.ms.provider.user.entity.User;
import com.learning.spring.cloud.ms.provider.user.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: UserController
 * Description:
 * Date: 2019/5/31 10:42 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserRepository userRepository;

    /**
     * http://localhost:8000/user/1
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public User findById(@PathVariable Long id) {
        return this.userRepository.findOne(id);
    }


    /**
     * http://localhost:8000/user/get?id=1&username=张三
     *
     * @param user
     * @return
     */
    @GetMapping("/get")
    public User get(User user) {
        return user;
    }

    /**
     * http://localhost:8000/user/post
     *
     * @param user
     * @return
     */
    @PostMapping("/post")
    public User post(@RequestBody User user) {
        return user;
    }
}
